<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if(!session_id()) { session_start(); }


//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.

if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}

if (empty($_POST)) {
	if (isset($_GET['edit_id'])) $values['attendee_id'] = $_GET['edit_id'];
	do_html_header('Modify Convention Badge info', staysmall, $uny);
	if (!get_con_reg_info($values['attendee_id'])) {
		echo $values['attendee_id'];
		print_modify_status_form($values);
		}
	else {
		print_modify_status_form(get_con_reg_info($values['attendee_id']));
		}
	do_html_footer(news);
	exit;
	}

//get some variables:
if (isset($_POST['event_day'])) $values['event_day'] = $_POST['event_day'];
if (isset($_POST['reg_type'])) $values['reg_type'] = $_POST['reg_type'];
if (isset($_POST['reg_status'])) $values['reg_status'] = $_POST['reg_status'];
if (isset($_POST['approve_events'])) $values['approve_events'] = $_POST['approve_events'];
if (isset($_POST['for_attendee_id'])) $values['for_attendee_id'] = $_POST['for_attendee_id'];
if (isset($_POST['reg_cost'])) $values['reg_cost'] = floatval($_POST['reg_cost']);
if (isset($_POST['special_entered'])) $values['special_entered'] = $_POST['special_entered'];


//Process event_day and figure out cost.
if ($values['reg_type'] == 'staff' || $values['reg_type'] == 'exhibitor' || $values['reg_type'] == 'special guest' || $values['reg_type'] == 'gm') {
	$values['event_day'] = 'all week-end';
	}
if ($values['reg_type'] == 'LARP only') {
	$values['event_day'] = 'saturday';
	}
	if ($values['reg_type'] != 'special') $values['reg_cost'] =    ($values['event_day'], $values['reg_type']);
if (empty($values['event_day']) || empty($values['reg_type'])) {
	do_html_header('Problem:', staysmall, $uny);
	echo '<span class="redtext">You must select both a registration day '
		 .'and a registration type Please try again.</span><br />';
	print_modify_status_form($values);
	do_html_footer(news);
	exit;
	}

if (($values['reg_type'] == 'special') && (!isset($values['reg_cost']) || empty($values['reg_cost'])) && !isset($values['special_entered'])) {
	do_html_header('Modify Convention Badge info', staysmall, $uny);
	print_special_cost_form($values);
	do_html_footer(news);
	exit;
	}



	if (get_con_reg_info($values['for_attendee_id'])) update_con_status($values['event_day'], $values['reg_status'], $values['for_attendee_id'], $values['reg_type'], $values['reg_cost'], $_SESSION['attendee_id']);
	if (!get_con_reg_info($values['for_attendee_id'])) insert_con_registration($values['for_attendee_id'], $values['event_day'], $values['reg_type'], $values['reg_cost'], $values['reg_status'], $_SESSION['attendee_id']);
	if ($values['approve_events'] == 'Y') {
		if ($result = get_attend_events($values['for_attendee_id'])); {
			$event_array = db_result_to_array($result);
			foreach ($event_array as $row) {
				update_event_reg_status($row['event_id'], $row['start_time'], $values['for_attendee_id'], $values['reg_status']);
				}
			}
		}
	$requested_id = $values['for_attendee_id'];
	header("Location: ".$conf['base_path']."registration/attendee_home.php?attendee_id=$requested_id");
?>